<template>
  <div class="wapper">
    <div class="title">我的订单</div>
    <div class="orders">
      <div class="order" v-for="(item, index) in list" :key="index">
        <div class="order__shopName">
          {{ item.shopName }}
          <span class="order__status">
            {{ item.isCanceled ? "已取消" : "已下单" }}
          </span>
        </div>
        <div class="order__content">
          <div class="order__content__imgs">
            <img
              class="order__content__img"
              v-for="(innerItem, innerIndex) in item.products"
              :src="innerItem.product.img"
              alt=""
              :key="innerIndex"
            />
          </div>
          <div class="order__info">
            <div class="order__info__price">￥{{ item.totalPrice }}</div>
            <div class="order__info__count">共{{ item.totalNum }}件</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <Docker :currentIndex="2" />
</template>
<script>
import Docker from "../../components/Docker";
import { get } from "../../utils/request";
import { reactive, toRefs } from "vue";
const useOrderListEffect = () => {
  const data = reactive({ list: [] });
  const getNeaybyList = async () => {
    const result = await get("/api/order");
    if (result?.errno === 0) {
      const orderList = result.data;
      orderList.forEach((order) => {
        let totalPrice = 0;
        let totalNum = 0;
        const products = order.products;
        products.forEach((elem) => {
          totalPrice = totalPrice + elem.product.price * elem.orderSales;
          totalNum = totalNum + elem.orderSales;
        });
        order.totalPrice = totalPrice;
        order.totalNum = totalNum;
      });
      data.list = result.data;
    }
  };
  getNeaybyList();
  const { list } = toRefs(data);

  return { list };
};
export default {
  name: "OrderList",
  components: { Docker },
  setup() {
    const { list } = useOrderListEffect();
    return { list };
  },
};
</script>
<style lang="scss" scoped>
@import "../../style/viriables.scss";
.wapper {
  overflow-y: scroll;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0.5rem;
  background-color: #eee;
  .title {
    margin-bottom: 0.16rem;
    line-height: 0.4rem;
    text-align: center;
    font-size: 0.16rem;
    color: $content-fontcolor;
    background-color: $white-color;
  }
  .order {
    padding: 0.16rem;
    margin: 0 0.18rem 0.16rem 0.18rem;
    background-color: $white-color;
    &__shopName {
      margin-bottom: 0.16rem;
      line-height: 0.22rem;
      font-size: 0.16rem;
      color: $content-fontcolor;
    }
    &__status {
      float: right;
      font-size: 0.14rem;
      color: #999;
    }
    &__content {
      display: flex;
      &__imgs {
        flex: 1;
        .order__content__img {
          width: 0.4rem;
          height: 0.4rem;
          margin-right: 0.12rem;
        }
      }
    }
    &__info {
      width: 0.7rem;
      line-height: 0.2rem;
      text-align: right;
      font-size: 0.14rem;
      color: $red-color;
      &__price {
        margin-bottom: 0.04rem;
      }
      &__count {
        color: $content-fontcolor;
        font-size: 0.12rem;
      }
    }
  }
}
</style>
